﻿using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HandlerOrderClient
{
    public class HandlerLastClient : SimpleChannelInboundHandler<IByteBuffer>
    {
        private int count = 0;
        protected override void ChannelRead0(IChannelHandlerContext ctx, IByteBuffer msg)
        {
            Console.WriteLine("HandlerLastClient1");
            // 如果第一次接收到数据,就给服务器发送client to server
            if (count == 0)
            {
                count++;
                ctx.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("client to server")));
            }
            Console.WriteLine("HandlerLastClient2");
        }
    }
}
